<!DOCTYPE html>
<html>
<head>
    {include file="Public/header"}
    <link rel="stylesheet" href="__STATIC__/layout/css/gyq.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
</head>

<body style="color:#333;padding:3px;font-size: 12px" class="x_sorll">
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">查看销售订单</h2>
</div>
<div style="margin-top:10px;">
    <a href="###" class="btn btn-info btn-sm">导出Excel</a>&nbsp;&nbsp;<a href="###" class="btn btn-info btn-sm">导出打印版</a>
</div>
<!-- 标题 -->
<div>

    <table class="row-margin-top tab-content table-bordered table" border="1" style="margin-bottom:0">
        <tr>
            <td style="min-width: 120px;width: 120px">编号</td>
            <td>{$data.sn}</td>
        </tr>
        <tr>
            <td>申请人：</td>
            <td>{$data.sqr}</td>
            <td>申请人部门：</td>
            <td>{$data.sqrbm}</td>
            <td>申请日期：</td>
            <td>{$data.sqrq}</td>
        </tr>
        <tr>
            <td>客户类型：</td>
            <td>{if $data.cusType==1}经销商{else}网点{/if}</td>
            <td>客户名称：</td>
            <td colspan="3">{$data.cusName}({$data.cusSN})</td>
        </tr>
        <tr>
            <td>发票类型：</td>
            <td colspan="5">{if $data.fpType==1}普通发票{elseif $data.fpType==2}增值税发票{/if}</td>
        </tr>
        <tr>
            <td>收货信息：</td>
            <td colspan="5">收货地址：{$data.shdz}；收货人：{$data.shr}；电话：{$data.dh}；</td>
        </tr>
        <tr>
            <td>建议发货日期：</td>
            <td>{$data.jyfhrq}</td>
            <td>订单状态：</td>
            <td>{if $data.status==0}草稿{/if}</td>
            <td>出库申请单：</td>
            <td><a href="{:url('kcgl/cksqd_view',['id'=>$data.cksqd_id])}" class="J_menuItem">{$data.cksqd_sn}</a></td>
        </tr>
        <tr>
            <td colspan="6" style="background-color:rgb(255,243,189);">
            经销商（{$data.cusName}）账上余额：未同步。？账期：未设定。信用额：未设定。查询经销商回款记录
            </td>
        </tr>
        <tr>
            <td colspan="6" >
                订单明细表列表
            </td>
        </tr>
    </table>

    <table class=" table table-striped table-bordered text-center ad_table" id="wzb" >
        <thead>
        <tr class="info">
            <th colspan="20" class="text-center font-bold">成品销售订单</th>
        </tr>
        <tr class="info">
            <th>明细编号</th>
            <th>品类</th>
            <th>产品编码</th>
            <th>产品名称</th>
            <th>对应订单<br>明细编号</th>
            <th>对应核销单<br>明细编号</th>
            <th>规格</th>
            <th>条形码</th>
            <th>单位</th>
            <th>原供价(元)</th>
            <th>现供价(元)</th>
            <th>类型</th>
            <th>订货数量</th>
            <th>搭赠数量</th>
            <th>原金额(元)</th>
            <th>应收金额(元)</th>
            <th>体积(立方米)</th>
            <th>重量(吨)</th>
            <th>备注</th>
        </tr>
        </thead>
        <tbody>
        {if isset($data)}
        {volist name="data.list" id="row"}
        <tr>
            <td>
                {$row.mxbh}
            </td>
            <td>
                {$row.category}
            </td>
            <td>
                {$row.prod_sn}
            </td>
            <td>
                {$row.pro_name}
            </td>
            <td>
                {$row.order_sn}
            </td>
            <td>
                {$row.order_sn}
            </td>
            <td>
                {$row.format}
            </td>
            <td>
                {$row.pro_sku}
            </td>
            <td>
                {$row.unit}
            </td>
            <td>
                {$row.ygj}
            </td>
            <td>
                {$row.xgj}
            </td>
            <td>
                {if $row.xslx==1}销售{elseif $row.xslx==2}搭赠{elseif $row.xslx==3}货补{elseif $row.xslx==4}补费{/if}
            </td>
            <td>
                {$row.num}
            </td>
            <td>
                {$row.dzsl}
            </td>
            <td>
                {$row.yje}
            </td>
            <td>
                {$row.ysje}
            </td>
            <td>{$row.box_volume}</td>
            <td>{$row.weight}</td>
            <td>{$row.beizhu}</td>
        </tr>
        {/volist}
        {volist name="data.huobu" id="row"}
        <tr>
            <td>
                {$row.mxbh}
            </td>
            <td>
                {$row.category}
            </td>
            <td>
                {$row.prod_sn}
            </td>
            <td>
                {$row.pro_name}
            </td>
            <td>
                {$row.order_sn}
            </td>
            <td>
                {$row.order_sn}
            </td>
            <td>
                {$row.format}
            </td>
            <td>
                {$row.pro_sku}
            </td>
            <td>
                {$row.unit}
            </td>
            <td>
                {$row.xgj}
            </td>
            <td>{$row.xgj}
            </td>
            <td>
                补货
            </td>
            <td>{$row.num}</td>
            <td></td>
            <td>{$row.yje}</td>
            <td>{$row.ysje}</td>
            <td>{$row.box_volume}</td>
            <td>{$row.weight}</td>
            <td>{$row.beizhu}</td>
        </tr>
        {/volist}
        {/if}
        <tr>
            <td>
            </td>
            <td colspan="8" class="text-right text-bold">小计：</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>{if isset($zj1)}{$zj1}{/if}</td>
            <td>{if isset($zj2)}{$zj2}{/if}</td>
            <td>{if isset($zj3)}{$zj3}{/if}</td>
            <td>{if isset($zj4)}{$zj4}{/if}</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        </tbody>
    </table>

    {if isset($data.bufei)&&count($data.bufei)>0}
    <table class="table table-striped table-bordered text-center ad_table">
        <thead>
        <tr class="info">
            <th colspan="7" class="text-center font-bold">补费明细</th>
        </tr>
        <tr class="info">
            <th>明细编号</th>

            <th>对应核销单编号</th>
            <th>类型</th>
            <th>补费金额(元)</th>
            <th>应收金额(元)</th>
            <th>备注</th>
        </tr>
        </thead>
        <tbody>

        {volist name="data.bufei" id="row"}
        <tr>
            <td>
                {$row.sn}
            </td>
            <td>
                <a href="{:url('Tihexiao/view',['id'=>$row.hxdmxbh])}" class="J_menuItem">{$row.hxdmxbh}</a>
            </td>
            <td>
                补费
            </td>
            <td>
                {$row.bfje}
            </td>
            <td>
                -{$row.bfje}
            </td>
            <td>
                {$row.beizhu}
            </td>
        </tr>
        {/volist}

        <tr>
            <td>

            </td>
            <td colspan="3">

            </td>
            <td>
                {if isset($xj)}{$xj}{/if}
            </td>
            <td>
                -{if isset($xj)}{$xj}{/if}
            </td>
            <td>
            </td>
        </tr>
        </tbody>
    </table>
    {/if}

    <table class="table-striped table-bordered text-center ad_table">
        <tr>
            <td style="width:120px;min-width:120px;">注意事项：</td>
            <td>{$data.zysx}</td>
        </tr>
    </table>

      <table class="table table-bordered text-left bud_hei">
            <tr class="info">
                <th class="text-left font-bold">审批意见</th>
            </tr>
            {volist name="logs" id="l"}
          <tr>
              <td>{$l.USERNAME} 审批动作：{$l.MEMO}；审批意见：{if $l.COMMENTS}{$l.COMMENTS}{else/}无{/if}(审批时间：{$l.ACTIONTIME})</td>
          </tr>
          
          {/volist}
      </table>

</div>
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/contabs_sub.js"></script>
<script>
    var link1 = '{:url("jxsjson")}'
    var link2 = '{:url("selectJXS")}'
</script>
<script>
    $('[name=cusType]').on('click',function () {
        if ($(this).val() == 1) {
            $('#kfplx').show()
            $('#cusName_queding').hide()
            $('#cusName_queding input').val('')
            $('#cusName_queding .inin').html('')
            $('#cusName_input').show()
            $('#cusName_input input').val('')
            //经销商搜索自动补全
            var cusName = [];
            $("#cusName").bsSuggest('destroy')
            $("#cusName").bsSuggest({
                url: link1,
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
                cusName = result.value
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword) {
                $('#cusName_queding').find('.inin').html(keyword.key)
                $('#cusName_queding').find('input').val(keyword.id)
                $('#cusName_queding').show()
                $('#cusName_input').hide()
                for(var i = 0;i<cusName.length;i++){
                    if(cusName[i].id==keyword.id){
                        $('[name=shdz]').val(cusName[i].lgs_rcv_addr)
                        $('[name=shr]').val(cusName[i].lgs_rcv_one)
                        $('[name=dh]').val(cusName[i].bs_rcv_phone)
                        // alert(cusName[i].invoicetype)
                        $('[name=fpType]:checked').val(cusName[i].invoicetype)
                        $('#fpType').html(cusName[i].invoicetype==1?'普通发票':'增值税发票')
                        //判断经销商是否有渠道优惠政策
                        $.post('{:url("hasyh")}',{jxs_id:keyword.id},function (data) {
                            if(data.success){
                                $("#yhPolicy").bsSuggest('destroy')
                                $("#yhPolicy").bsSuggest({
                                    url: '{:url("yhPolicy")}?jxs_id='+keyword.id,
                                    effectiveFields: ["id", "title"],
                                    searchFields: [ "title"],
                                    effectiveFieldsAlias: {title: "名称"},
                                    ignorecase: true,
                                    showHeader: true,
                                    showBtn: false,     //不显示下拉按钮
                                    delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                    idField: "id",
                                    keyField: "title",
                                    clearable: true
                                }).on('onDataRequestSuccess', function (e, result) {
                                    console.log('onDataRequestSuccess: ', result);
                                }).on('onSetSelectValue', function (e, keyword) {
                                    $('#yh_queding').find('.inin').html(keyword.key)
                                    $('#yh_queding').find('input').val(keyword.id)
                                    $('#yh_queding').show()
                                    $('#yh_input').hide()
                                    $('#yh_input').find('input').val('')
                                }).on('onUnsetSelectValue', function () {
                                    console.log("onUnsetSelectValue");
                                });
                                //关闭渠道优惠政策选择
                                $('#yh_queding .close').click(function () {
                                    $(this).closest('#yh_queding').hide().find('.inin').html('')
                                    $('#yh_queding').find('input').val('')
                                    $('#yh_input').show().find('input').val('')
                                })
                                //弹出渠道优惠政策树
                                $('#selectyh').off('click')
                                $('#selectyh').on('click',function () {
                                    top.layer.open({
                                        type:2,
                                        area:['60%','60%'],
                                        maxmin:true,
                                        content:'{:url("open/yhpolicy")}?jxs_id='+keyword.id,
                                        btn:['确定','关闭'],
                                        yes:function (i,o) {
                                            var a = $(o).find('iframe').contents()
                                            var id =  a.find("#renyuan").val();
                                            var name =  a.find("#renyuanname").val();
                                            if(id){
                                                $('#yh_queding').find('.inin').html(name)
                                                $('#yh_queding').find('input').val(id)
                                                $('#yh_queding').show()
                                                $('#yh_input').hide()
                                                $('#yh_input').find('input').val('')
                                            }
                                            top.layer.close(i)
                                        }
                                    })
                                    return  false
                                })
                                $('#hasyh').show()
                                $('#noyh').hide()
                            }else{
                                $('#hasyh').hide()
                                $('#noyh').show()
                            }

                            $('#hide1').show()
                        },'json')
                    }
                }

            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });

            $('#selectCus').off('click')
            //弹出经销商树
            $('#selectCus').click(function () {
                top.layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:link2,
                    btn:['确定','关闭'],
                    yes:function (i,o) {
                        var a = $(o).find('iframe').contents()
                        var id =  a.find("#renyuan").val();
                        var name =  a.find("#renyuanname").val();
                        if(id){
                            $('#cusName_queding').find('.inin').html(name)
                            $('#cusName_queding').find('input').val(id)
                            $('#cusName_queding').show()
                            $('#cusName_input').hide()

                            //判断经销商是否有渠道优惠政策
                            $.post('{:url("hasyh")}',{jxs_id:id},function (data) {
                                if(data.success){
                                    $("#yhPolicy").bsSuggest('destroy')
                                    $("#yhPolicy").bsSuggest({
                                        url: '{:url("yhPolicy")}?jxs_id='+id,
                                        effectiveFields: ["id", "title"],
                                        searchFields: [ "title"],
                                        effectiveFieldsAlias: {title: "名称"},
                                        ignorecase: true,
                                        showHeader: true,
                                        showBtn: false,     //不显示下拉按钮
                                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                        idField: "id",
                                        keyField: "title",
                                        clearable: true
                                    }).on('onDataRequestSuccess', function (e, result) {
                                        console.log('onDataRequestSuccess: ', result);
                                    }).on('onSetSelectValue', function (e, keyword) {
                                        $('#yh_queding').find('.inin').html(keyword.key)
                                        $('#yh_queding').find('input').val(keyword.id)
                                        $('#yh_queding').show()
                                        $('#yh_input').hide()
                                        $('#yh_input').find('input').val('')
                                    }).on('onUnsetSelectValue', function () {
                                        console.log("onUnsetSelectValue");
                                    });
                                    //关闭渠道优惠政策选择
                                    $('#yh_queding .close').click(function () {
                                        $(this).closest('#yh_queding').hide().find('.inin').html('')
                                        $('#yh_queding').find('input').val('')
                                        $('#yh_input').show().find('input').val('')
                                    })
                                    //弹出渠道优惠政策树
                                    $('#selectyh').off('click')
                                    $('#selectyh').on('click',function () {
                                        top.layer.open({
                                            type:2,
                                            area:['60%','60%'],
                                            maxmin:true,
                                            content:'{:url("open/yhpolicy")}?jxs_id='+id,
                                            btn:['确定','关闭'],
                                            yes:function (i,o) {
                                                var a = $(o).find('iframe').contents()
                                                var id =  a.find("#renyuan").val();
                                                var name =  a.find("#renyuanname").val();
                                                if(id){
                                                    $('#yh_queding').find('.inin').html(name)
                                                    $('#yh_queding').find('input').val(id)
                                                    $('#yh_queding').show()
                                                    $('#yh_input').hide()
                                                    $('#yh_input').find('input').val('')
                                                }
                                                top.layer.close(i)
                                            }
                                        })
                                        return  false
                                    })
                                    $('#hasyh').show()
                                    $('#noyh').hide()
                                }else{
                                    $('#hasyh').hide()
                                    $('#noyh').show()
                                }

                                $('#hide1').show()
                            },'json')
                        }
                        top.layer.close(i)
                    }
                })
                return  false
            })
        }else {
            $('#kfplx').hide()
            $('#cusName_queding').hide()
            $('#cusName_queding input').val('')
            $('#cusName_queding .inin').html('')
            $('#cusName_input').show()
            $('#cusName_input input').val('')
            $("#cusName").bsSuggest('destroy')
            $("#cusName").bsSuggest({
                url: '{:url("bs/net")}',
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
                cusName = result.value
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword) {
                $('#cusName_queding').find('.inin').html(keyword.key)
                $('#cusName_queding').find('input').val(keyword.id)
                $('#cusName_queding').show()
                $('#cusName_input').hide()
                for(var i = 0;i<cusName.length;i++){
                    if(cusName[i].id==keyword.id){
                        $('[name=shdz]').val(cusName[i].lgs_rcv_addr)
                        $('[name=shr]').val(cusName[i].lgs_rcv_one)
                        $('[name=dh]').val(cusName[i].bs_rcv_phone)
                        // alert(cusName[i].invoicetype)
                        $('[name=fpType]:checked').val(cusName[i].invoicetype)
                        $('#fpType').html(cusName[i].invoicetype==1?'普通发票':'增值税发票')
                        //判断经销商是否有渠道优惠政策
                        $.post('{:url("hasyh")}',{jxs_id:keyword.id},function (data) {
                            if(data.success){
                                $("#yhPolicy").bsSuggest('destroy')
                                $("#yhPolicy").bsSuggest({
                                    url: '{:url("yhPolicy")}?jxs_id='+keyword.id,
                                    effectiveFields: ["id", "title"],
                                    searchFields: [ "title"],
                                    effectiveFieldsAlias: {title: "名称"},
                                    ignorecase: true,
                                    showHeader: true,
                                    showBtn: false,     //不显示下拉按钮
                                    delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                    idField: "id",
                                    keyField: "title",
                                    clearable: true
                                }).on('onDataRequestSuccess', function (e, result) {
                                    console.log('onDataRequestSuccess: ', result);
                                }).on('onSetSelectValue', function (e, keyword) {
                                    $('#yh_queding').find('.inin').html(keyword.key)
                                    $('#yh_queding').find('input').val(keyword.id)
                                    $('#yh_queding').show()
                                    $('#yh_input').hide()
                                    $('#yh_input').find('input').val('')
                                }).on('onUnsetSelectValue', function () {
                                    console.log("onUnsetSelectValue");
                                });
                                //关闭渠道优惠政策选择
                                $('#yh_queding .close').click(function () {
                                    $(this).closest('#yh_queding').hide().find('.inin').html('')
                                    $('#yh_queding').find('input').val('')
                                    $('#yh_input').show().find('input').val('')
                                })
                                //弹出渠道优惠政策树
                                $('#selectyh').off('click')
                                $('#selectyh').on('click',function () {
                                    top.layer.open({
                                        type:2,
                                        area:['60%','60%'],
                                        maxmin:true,
                                        content:'{:url("open/yhpolicy")}?jxs_id='+keyword.id,
                                        btn:['确定','关闭'],
                                        yes:function (i,o) {
                                            var a = $(o).find('iframe').contents()
                                            var id =  a.find("#renyuan").val();
                                            var name =  a.find("#renyuanname").val();
                                            if(id){
                                                $('#yh_queding').find('.inin').html(name)
                                                $('#yh_queding').find('input').val(id)
                                                $('#yh_queding').show()
                                                $('#yh_input').hide()
                                                $('#yh_input').find('input').val('')
                                            }
                                            top.layer.close(i)
                                        }
                                    })
                                    return  false
                                })
                                $('#hasyh').show()
                                $('#noyh').hide()
                            }else{
                                $('#hasyh').hide()
                                $('#noyh').show()
                            }

                            $('#hide1').show()
                        },'json')
                    }
                }

            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });

            $('#selectCus').off('click')
            //弹出经销商树
            $('#selectCus').on('click',function () {
                top.layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content: '{:url("open/net2")}',
                    btn:['确定','关闭'],
                    yes:function (i,o) {
                        var a = $(o).find('iframe').contents()
                        var id =  a.find("#renyuan").val();
                        var name =  a.find("#renyuanname").val();
                        if(id){
                            $('#cusName_queding').find('.inin').html(name)
                            $('#cusName_queding').find('input').val(id)
                            $('#cusName_queding').show()
                            $('#cusName_input').hide()
                            $('#hasyh').hide()
                            $('#noyh').show()
                        }
                        top.layer.close(i)
                    }
                })
                return  false
            })
        }
    })
    $('#fanhui').on('click',function () {
        location.href='{:url("index")}'
    })
    //删除
    $('.shanchu').on('click',function () {
        var link = $(this).data('link')
        $.post(link,function (data) {
            if(data.success){
                swal({title:data.msg},function () {
                    location.reload()
                })
            }else{
                swal(data.msg)
            }
        },'json')
    })
    //修改
    $('.xiugai').on('click',function () {
        var link = $(this).data('link')
        var jxs_id = $('input[name=cusName]').val()
        layer.open({
            type: 2,
            title: '修改明细',
            skin: 'layui-layer-rim', //加上边框
            area: ['800px', '500px'], //宽高
            content: link+'?jxs_id='+jxs_id
        });
    })
    $('.save').on('click',function () {
        var param = $(this).closest('form').serialize()
        $.post('',param,function (data) {
            if(data.success){
                swal({title:data.msg},function () {
                    location.href='{:url("index")}'
                })
            }else{
                swal(data.msg)
            }
        },'json')
        return false;
    })
    $(function () {
        //经销商搜索自动补全
        var cusName = [];
        $("#cusName").bsSuggest({
            url: link1,
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            cusName = result.value
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            $('#cusName_queding').find('.inin').html(keyword.key)
            $('#cusName_queding').find('input').val(keyword.id)
            $('#cusName_queding').show()
            $('#cusName_input').hide()
            for(var i = 0;i<cusName.length;i++){
                if(cusName[i].id==keyword.id){
                    $('[name=shdz]').val(cusName[i].lgs_rcv_addr)
                    $('[name=shr]').val(cusName[i].lgs_rcv_one)
                    $('[name=dh]').val(cusName[i].bs_rcv_phone)
                    // alert(cusName[i].invoicetype)
                    $('[name=fpType]:checked').val(cusName[i].invoicetype)
                    $('#fpType').html(cusName[i].invoicetype==1?'普通发票':'增值税发票')
                    //判断经销商是否有渠道优惠政策
                    $.post('{:url("hasyh")}',{jxs_id:keyword.id},function (data) {
                        if(data.success){
                            $("#yhPolicy").bsSuggest('destroy')
                            $("#yhPolicy").bsSuggest({
                                url: '{:url("yhPolicy")}?jxs_id='+keyword.id,
                                effectiveFields: ["id", "title"],
                                searchFields: [ "title"],
                                effectiveFieldsAlias: {title: "名称"},
                                ignorecase: true,
                                showHeader: true,
                                showBtn: false,     //不显示下拉按钮
                                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                idField: "id",
                                keyField: "title",
                                clearable: true
                            }).on('onDataRequestSuccess', function (e, result) {
                                console.log('onDataRequestSuccess: ', result);
                            }).on('onSetSelectValue', function (e, keyword) {
                                $('#yh_queding').find('.inin').html(keyword.key)
                                $('#yh_queding').find('input').val(keyword.id)
                                $('#yh_queding').show()
                                $('#yh_input').hide()
                                $('#yh_input').find('input').val('')
                            }).on('onUnsetSelectValue', function () {
                                console.log("onUnsetSelectValue");
                            });
                            //关闭渠道优惠政策选择
                            $('#yh_queding .close').click(function () {
                                $(this).closest('#yh_queding').hide().find('.inin').html('')
                                $('#yh_queding').find('input').val('')
                                $('#yh_input').show().find('input').val('')
                            })
                            //弹出渠道优惠政策树
                            $('#selectyh').off('click')
                            $('#selectyh').on('click',function () {
                                top.layer.open({
                                    type:2,
                                    area:['60%','60%'],
                                    maxmin:true,
                                    content:'{:url("open/yhpolicy")}?jxs_id='+keyword.id,
                                    btn:['确定','关闭'],
                                    yes:function (i,o) {
                                        var a = $(o).find('iframe').contents()
                                        var id =  a.find("#renyuan").val();
                                        var name =  a.find("#renyuanname").val();
                                        if(id){
                                            $('#yh_queding').find('.inin').html(name)
                                            $('#yh_queding').find('input').val(id)
                                            $('#yh_queding').show()
                                            $('#yh_input').hide()
                                            $('#yh_input').find('input').val('')
                                        }
                                        top.layer.close(i)
                                    }
                                })
                                return  false
                            })
                            $('#hasyh').show()
                            $('#noyh').hide()
                        }else{
                            $('#hasyh').hide()
                            $('#noyh').show()
                        }

                        $('#hide1').show()
                    },'json')
                }
            }

        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        //关闭经销商选择
        $('#cusName_queding .close').click(function () {
            $(this).closest('#cusName_queding').hide().find('.inin').html('')
            $('#cusName_input').show().find('input').val('')
        })

        $('#selectCus').off('click')
        //弹出经销商树
        $('#selectCus').click(function () {
            top.layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:link2,
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        $('#cusName_queding').find('.inin').html(name)
                        $('#cusName_queding').find('input').val(id)
                        $('#cusName_queding').show()
                        $('#cusName_input').hide()

                        //判断经销商是否有渠道优惠政策
                        $.post('{:url("hasyh")}',{jxs_id:id},function (data) {
                            if(data.success){
                                $("#yhPolicy").bsSuggest('destroy')
                                $("#yhPolicy").bsSuggest({
                                    url: '{:url("yhPolicy")}?jxs_id='+id,
                                    effectiveFields: ["id", "title"],
                                    searchFields: [ "title"],
                                    effectiveFieldsAlias: {title: "名称"},
                                    ignorecase: true,
                                    showHeader: true,
                                    showBtn: false,     //不显示下拉按钮
                                    delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                    idField: "id",
                                    keyField: "title",
                                    clearable: true
                                }).on('onDataRequestSuccess', function (e, result) {
                                    console.log('onDataRequestSuccess: ', result);
                                }).on('onSetSelectValue', function (e, keyword) {
                                    $('#yh_queding').find('.inin').html(keyword.key)
                                    $('#yh_queding').find('input').val(keyword.id)
                                    $('#yh_queding').show()
                                    $('#yh_input').hide()
                                    $('#yh_input').find('input').val('')
                                }).on('onUnsetSelectValue', function () {
                                    console.log("onUnsetSelectValue");
                                });
                                //关闭渠道优惠政策选择
                                $('#yh_queding .close').click(function () {
                                    $(this).closest('#yh_queding').hide().find('.inin').html('')
                                    $('#yh_queding').find('input').val('')
                                    $('#yh_input').show().find('input').val('')
                                })
                                //弹出渠道优惠政策树
                                $('#selectyh').off('click')
                                $('#selectyh').on('click',function () {
                                    top.layer.open({
                                        type:2,
                                        area:['60%','60%'],
                                        maxmin:true,
                                        content:'{:url("open/yhpolicy")}?jxs_id='+id,
                                        btn:['确定','关闭'],
                                        yes:function (i,o) {
                                            var a = $(o).find('iframe').contents()
                                            var id =  a.find("#renyuan").val();
                                            var name =  a.find("#renyuanname").val();
                                            if(id){
                                                $('#yh_queding').find('.inin').html(name)
                                                $('#yh_queding').find('input').val(id)
                                                $('#yh_queding').show()
                                                $('#yh_input').hide()
                                                $('#yh_input').find('input').val('')
                                            }
                                            top.layer.close(i)
                                        }
                                    })
                                    return  false
                                })
                                $('#hasyh').show()
                                $('#noyh').hide()
                            }else{
                                $('#hasyh').hide()
                                $('#noyh').show()
                            }

                            $('#hide1').show()
                        },'json')
                    }
                    top.layer.close(i)
                }
            })
            return  false
        })

        //经销商搜索自动补全--修改时
        {if request()->param("id")}
        $("#yhPolicy").bsSuggest({
            url: '{:url("yhPolicy",["jxs_id"=>$data.cusName])}',
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            $('#yh_queding').find('.inin').html(keyword.key)
            $('#yh_queding').find('input').val(keyword.id)
            $('#yh_queding').show()
            $('#yh_input').hide()
            $('#yh_input').find('input').val('')
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        //关闭渠道优惠政策选择
        $('#yh_queding .close').click(function () {
            $(this).closest('#yh_queding').hide().find('.inin').html('')
            $('#yh_queding').find('input').val('')
            $('#yh_input').show().find('input').val('')
        })

        //弹出渠道优惠政策树
        $('#selectyh').click(function () {
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("open/yhpolicy",["jxs_id"=>$data.cusName])}',
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        $('#yh_queding').find('.inin').html(name)
                        $('#yh_queding').find('input').val(id)
                        $('#yh_queding').show()
                        $('#yh_input').hide()
                        $('#yh_input').find('input').val('')
                    }
                    top.layer.close(i)
                }
            })
            return  false
        })
        {/if}
    })
    function back() {
        history.go(-1)
    }

    laydate({
        elem: "#startTime",
        event: "focus"
    })

    var AgencyName = $("#AgencyName");
    sousuo(AgencyName)

    function sousuo(id) {
        id.bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: true, //以分隔符号分割的多关键字支持
            separator: ",", //多关键字支持时的分隔符，默认为空格
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            url: 'http://unionsug.baidu.com/su?p=3&t=' + (new Date()).getTime() + '&wd=',
            /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/
            jsonp: 'cb',
            /*如果从 url 获取数据，并且需要跨域，则该参数必须设置*/
            processData: function (json) { // url 获取数据时，对数据的处理，作为 getData 的回调函数
                var i, len, data = {
                    value: []
                };
                if (!json || !json.s || json.s.length === 0) {
                    return false;
                }

                // console.log(json);
                len = json.s.length;

                jsonStr = "{'value':[";
                for (i = 0; i < len; i++) {
                    data.value.push({
                        word: json.s[i]
                    });
                }
                data.defaults = 'baidu';

                //字符串转化为 js 对象
                return data;
            }
        });

    }

    $("#addsall").click(function () {
        if ($("[name=cusName]").val() == "") {
            swal("", "客户名称不能为空！", "error")
        }   else if ($("[name=shdz]").val() == "") {
            swal("", "收货地址不能为空！", "error")
        } else if ($("[name=shr]").val() == "") {
            swal("", "收货人不能为空！", "error")
        } else if ($("[name=dh]").val() == "") {
            swal("", "电话不能为空！", "error")
        } else {
            var jxs_id = $('[name=cusName]').val()
            var yhPolicy = $('[name=yhPolicy]').val()
            layer.open({
                type: 2,
                title: '添加销售订单明细',
                skin: 'layui-layer-rim', //加上边框
                area: ['900px', '500px'], //宽高
                maxmin:true,
                content: '{:url("add_Dd_detail")}?jxs_id='+jxs_id
            });
        }
    })

    //添加货补
    $("#addhuobu").click(function () {
        var id = $('#id').val()
        if($('#id').val()==''){
            swal("", "请先添加订货明细！", "error")
            return false
        }
        if ($("#gys").val() == "") {
            swal("", "供应商不能为空！", "error")
        } else if ($("#wlKind").val() == "") {
            swal("", "物料类别不能为空！", "error")
        } else if ($("#gysAddr").val() == "") {
            swal("", "供应商地址不能为空！", "error")
        } else if ($("#concact").val() == "") {
            swal("", "联系人不能为空！", "error")
        } else if ($("#tell").val() == "") {
            swal("", "电话不能为空！", "error")
        } else if ($("#them").val() == "") {
            swal("", "主题(采购原因)不能为空！", "error")
        } else {
            var cusName = $('[name=cusName]').val()
            layer.open({
                type: 2,
                title: '添加货补订单明细',
                skin: 'layui-layer-rim', //加上边框
                area: ['800px', '500px'], //宽高
                content: '{:url("buhuo_detail")}?id='+id+'&jxs_id='+cusName
            });
        }
    })
    $("#addbuhuo").click(function () {
        var id = $('#id').val()
        var cusName = $('[name=cusName]').val()
        if (cusName == "") {
            swal("", "请选择客户名称！", "error")
            return false
        }
        layer.open({
            type: 2,
            title: '添加补费订单明细',
            skin: 'layui-layer-rim', //加上边框
            area: ['800px', '500px'], //宽高
            content: '{:url("bufei_Dd_detail")}?id='+id+'&jxs_id='+cusName
        });
    })
</script>
</body>

</html>
<!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script>
    // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });

    });
</script>